package com.oocl.euc.core.builder;

import com.oocl.euc.common.constant.RequestFormStatus;
import com.oocl.euc.core.maintenance.model.Users;
import com.oocl.euc.core.requestform.model.RequestAttachment;
import com.oocl.euc.core.requestform.model.RequestForm;
import com.oocl.euc.core.requestform.model.RequestPostmortem;
import com.oocl.euc.core.requestform.model.RequestProcedures;
import com.oocl.euc.core.requestform.repository.RequestFormRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

@Component
public class RequestFormBuilder {

    public static final String CATEGORY_ID = "categoryId";
    public static final String SUBCATEGORY_ID = "subCategoryId";
    public static final String USER1 = "ZHOUSK";
    public static final String USER2 = "WUNE";
    public static final String ENDORSER_LIST = "ZHOUSK;WUNE;ZHOUSK";
    public static final String COPY_TO = "ZHOUSK";
    public static final String TEST_STRING = "test";
    public static final String USER2_EAMIL = "Neal.WU@oocl.com";
    public static final String CHANGE_TYPE = "Planed";
    public static final String TEAM = "EUCD";
    private static final String TEST_STRING_CHANGE = "testChange";
    private RequestForm requestForm;
    @Autowired
    RequestFormRepository requestFormRepository;

    public RequestFormBuilder defaultBuilder() {

        requestForm = new RequestForm();
        this.requestForm.setRequesterDomainId("LINCO");
        this.requestForm.setRequestStatus(RequestFormStatus.PENDING);
        this.requestForm.setEndorsedBy(TEAM);
        this.requestForm.setEndorserList("SKY ZHOU");
        this.requestForm.setChangeClassification("other");
        this.requestForm.setChangeType(CHANGE_TYPE);
        this.requestForm.setChangeObjective(TEST_STRING);
        this.requestForm.setCategoryId("Server");
        this.requestForm.setSubcategoryId("VM");

        return this;
    }

    public RequestFormBuilder builderForEmailTest1() {

        requestForm = new RequestForm();
        this.requestForm.setRequesterDomainId(USER1);
        this.requestForm.setRequestStatus(RequestFormStatus.PENDING);
        this.requestForm.setEndorsedBy(TEAM);
        this.requestForm.setEndorserList(ENDORSER_LIST);
        this.requestForm.setChangeClassification(TEST_STRING);
        this.requestForm.setChangeType(CHANGE_TYPE);
        this.requestForm.setChangeObjective(TEST_STRING);
        this.requestForm.setCategoryId(CATEGORY_ID);
        this.requestForm.setSubcategoryId(SUBCATEGORY_ID);
        requestForm.setCopyTo(COPY_TO);
        requestForm.setEmail(USER2_EAMIL);
        return this;
    }

    public RequestFormBuilder builderForEmailTest() {

        requestForm = new RequestForm();
        this.requestForm.setRequesterDomainId(USER1);
        this.requestForm.setRequestStatus(RequestFormStatus.PENDING);
        this.requestForm.setEndorsedBy(TEAM);
        this.requestForm.setEndorserList(ENDORSER_LIST);
        this.requestForm.setChangeType(CHANGE_TYPE);
        this.requestForm.setChangeClassification(TEST_STRING);
        this.requestForm.setChangeObjective(TEST_STRING);
        this.requestForm.setCategoryId(CATEGORY_ID);
        this.requestForm.setSubcategoryId(SUBCATEGORY_ID);
        requestForm.setCopyTo(COPY_TO);
        requestForm.setEmail(USER2_EAMIL);

        requestForm.setSecondVerifier(USER1);
        requestForm.setFirstVerifier(USER1);
        requestForm.setFirstVerificationReason(TEST_STRING);
        requestForm.setFirstVerificationImpact(TEST_STRING);
        requestForm.setVerificationReason(TEST_STRING);
        requestForm.setVerificationImpact(TEST_STRING);
        requestForm.setApproveImpactBy(TEST_STRING);
        requestForm.setChgCtlRef(TEST_STRING);
        requestForm.setRiskAssessmentReviewResult(TEST_STRING_CHANGE);
        requestForm.setOldRiskAssessmentReviewResult(TEST_STRING);
        requestForm.setRiskAssessmentRemark(TEST_STRING_CHANGE);
        requestForm.setOldRiskAssessmentRemark(TEST_STRING);

        requestForm.setRiskAssessmentProgress(TEST_STRING_CHANGE);
        requestForm.setOldRiskAssessmentProgress(TEST_STRING);
        requestForm.setRiskLevel(TEST_STRING_CHANGE);
        requestForm.setOldRiskLevel(TEST_STRING);
        requestForm.setRequestStatus(TEST_STRING_CHANGE);
        requestForm.setOldStatus(TEST_STRING);
        requestForm.setChangeObjective(TEST_STRING_CHANGE);
        requestForm.setOldChangeObjective(TEST_STRING);
        requestForm.setRefNO(TEST_STRING);
        requestForm.setTtNumber(TEST_STRING);
        requestForm.setChangeImportantFieldsAndQAPPBy(TEST_STRING);
        requestForm.setUpdatedBy(new Users());
        requestForm.setChangeClassification(TEST_STRING);
        requestForm.setChangeObjective(TEST_STRING);
        requestForm.setOnlineServiceImpact(TEST_STRING);

        requestForm.setOnlineServiceImpactFromDate(new Date());
        requestForm.setOnlineServiceImpactToDate(new Date());

        requestForm.setApplicationImpact(TEST_STRING);
        requestForm.setOldOnlineServiceImpact(TEST_STRING);
        requestForm.setOldApplicationServiceImpact(TEST_STRING);
        requestForm.setHasOnlineServiceImpact(TEST_STRING);
        requestForm.setHasApplicationImpact(TEST_STRING);
        requestForm.setOldHasOnlineServiceImpact(TEST_STRING);
        requestForm.setOldHasApplicationImpact(TEST_STRING);
        requestForm.setRequestStatus(TEST_STRING);

        requestForm.setExpectedDate(new Date());

        requestForm.setOldPPRunResult(TEST_STRING);
        requestForm.setPpTrialRunResult(TEST_STRING);
        requestForm.setOldQATestingResult(TEST_STRING);
        requestForm.setTestingResult(TEST_STRING);

        requestForm.setOldCategoryName(TEST_STRING);
        requestForm.setOldSubCategoryName(TEST_STRING);
        requestForm.setChangeWorkingStatusBy(TEST_STRING);
        requestForm.setChangeStatusBy(TEST_STRING);
        requestForm.setChangeChgcntlBy(TEST_STRING);

        return this;
    }

    public RequestFormBuilder withRequestStatus(String requestStatus){
        this.requestForm.setRequestStatus(requestStatus);
        return this;
    }

    public RequestFormBuilder withRefNO(String refNO) {
        this.requestForm.setRefNO(refNO);
        return this;
    }

    public RequestFormBuilder withRequestDomainID(String domainID) {
        this.requestForm.setRequesterDomainId(domainID);
        return this;
    }

    public RequestFormBuilder withRequestAttachments(List<RequestAttachment> requestAttachmentList) {
        this.requestForm.setRequestattachments(requestAttachmentList);
        return this;
    }

    public RequestFormBuilder withRequestPostmortems(List<RequestPostmortem> requestPostmortemList) {
        this.requestForm.setRequestpostmortem(requestPostmortemList);
        return this;
    }

    public RequestFormBuilder withRequestprocedures(List<RequestProcedures> requestProceduresList) {
        this.requestForm.setRequestprocedures(requestProceduresList);
        return this;
    }

    public RequestFormBuilder withCatagoryId(String catagoryId) {
        this.requestForm.setCategoryId(catagoryId);
        return this;
    }

    public RequestFormBuilder withSubCatagoryId(String subCatagoryId) {
        this.requestForm.setSubcategoryId(subCatagoryId);
        return this;
    }

    public RequestFormBuilder withExpectedDate(Date expectedDate) {

        this.requestForm.setExpectedDate(expectedDate);
        return this;
    }

    public RequestFormBuilder withExpectedTime(String expectedTime) {
        this.requestForm.setExpectedTime(expectedTime);
        return this;
    }

    public RequestFormBuilder withOnlineServerImpact(String onlineServerImpact) {
        this.requestForm.setOnlineServiceImpact(onlineServerImpact);
        return this;
    }

    public RequestFormBuilder withOnlineServiceImpactFromDate(Date onlineServerImapctFromDate) {
        this.requestForm.setOnlineServiceImpactFromDate(onlineServerImapctFromDate);
        return this;
    }

    public RequestFormBuilder withOnlineServiceImpactToDate(Date onlineServerImpactToDate) {
        this.requestForm.setOnlineServiceImpactToDate(onlineServerImpactToDate);
        return this;
    }

    public RequestFormBuilder withTestingResult(String testResult) {
        this.requestForm.setTestingResult(testResult);
        return this;
    }

    public RequestFormBuilder withPpTrialRunResult(String ppRialResult) {
        this.requestForm.setPpTrialRunResult(ppRialResult);
        return this;
    }

    public RequestFormBuilder withEmail(String email) {
        this.requestForm.setEmail(email);
        return this;
    }

    public RequestForm create() {
        return this.requestForm;
    }

    public RequestForm saveToDB() {
        requestFormRepository.save(this.requestForm);
        return this.requestForm;
    }
}
